package com.demo;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class HelloAspect {
    //第一个*号表示任何返回参数
    //第二个*表示任何类
    //第三个*表示任何方法
    //demo后..表示demo下的所有包
    @Pointcut("execution(* com.demo..*.*(..)) ")
    public void point() {

    }

    @Before("point()")
    public void before() {
        System.out.println("this is from HelloAspect#before...");
    }

    @After("point()")
    public void after() {
        System.out.println("this is from HelloAspect#after...");
    }

    @AfterReturning("point()")
    public void afterReturning() {
        System.out.println("this is from HelloAspect#afterReturning...");
    }

    @AfterThrowing("point()")
    public void afterThrowing() {
        System.out.println("this is from HelloAspect#afterThrowing...");
    }

    // 此处需要注意：若写了@Around方法，那么最后只会执行@Around和@AfterReturning 其它的都不会执行
    @Around("point()")
    public void around(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("this is from HelloAspect#around begin...");
        pjp.proceed();
        System.out.println("this is from HelloAspect#around after...");
    }

}
